<?php

namespace App\Http\Controllers;

use App\Services\ProjectService;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;

class CaseLibraryController extends BaseController
{
    /**
     * 案例库列表
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-09-25
     * @return void
     */
    public function caseLibrary(Request $request)
    {
        $rules = [
            'page' => ['required'],
            'limit' => ['required'],
            // 'project_name' => ['required'],
        ];

        $message = [
            'page.required' => '页码不能为空',
            'limit.required' => '限制条数不能为空',
            // 'project_name.required' => '',
        ];

        $payload = $request->only('page', 'limit', 'project_name');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }
        return successPaginate(ProjectService::getProjectCaseList($payload));
    }



    /**
     * 案例库详情
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2025-01-09
     * @param Request $request
     * @return void
     */
    public function serviceCaseDetail(Request $request)
    {
        $rules = [
            'id' => ['required'],
        ];

        $message = [
            'id.required' => '缺少参数ID',
        ];

        $payload = $request->only('id');

        $validator = Validator::make($payload, $rules, $message);

        // 验证格式
        if ($validator->fails()) {
            return fail_message($validator->errors()->first());
        }

        $result = ProjectService::getProjectDetail($payload['id']);
        // dd($result);
        if ($result) {
            return success($result);
        } else {
            return fail_message();
        }
    }
}
